package copyengine.ui.component
{
    import copyengine.utils.ICEDispose;

    import starling.display.DisplayObject;

    /**
     * 该类为所有的UI组件的基类
     * 每个UI组件本身并不是显示对象,其内部通过mContainer引用挂在显示树上的Mc
     */
    public class CEUIComponent implements ICEDispose
    {
        private var mContainer:DisplayObject;

        //只Dispose一次
        private var mIsDisposed:Boolean;

        public function CEUIComponent(_container:DisplayObject)
        {
            mContainer = _container;
        }

        //============================================//
        //==Public Interface  Function
        //============================================//
        public final function dispose():void
        {
            if (!mIsDisposed) {
                doDispose();
                mContainer.dispose();
                mIsDisposed = true;
            }
        }

        //========================//
        //== UIComponent 本身不是显示对象
        //== 提供以下这些方法是为了更方便操作
        //========================//
        public final function removeFromParent(_isDispose:Boolean = false):void { mContainer.removeFromParent(_isDispose); }

        public final function get container():DisplayObject { return mContainer; }

        public final function get visible():Boolean { return mContainer.visible; }

        public final function set visible(_isVisible:Boolean):void {mContainer.visible = _isVisible;}

        public final function set x(_val:Number):void { mContainer.x = _val; }

        public final function get x():Number { return mContainer.x; }

        public final function set y(_val:Number):void { mContainer.y = _val; }

        public final function get y():Number { return mContainer.y; }

        public final function get name():String {return mContainer.name;}

        //============================================//
        //==OverrideAble  Function
        //============================================//

        protected function doDispose():void {}
    }
}
